refactore code to get number from input