Added logic to check valid input