added a bit more input validation, and removed excess debug prints
further input validation