If user type in 0 the output was empty. This bug is fixed. In addition I refactored and documented the code.