improved error and input handling/valiation