Fixed issues with certain input values

Fixed an issue where if 0 was an input, nothing would get printed out.
Also broke parts of the code into functions.