Io credo che al posto di "<" dovresti metter ">" nell'ultimo if anche se non sono molto sicuro.