Fix whitespaces and indent
Simplify logic, add some protection to user input parameters