more formatting tweaks
better input validation, remove unnecessary code