fix error on bad input, add relevant test