Added a bit of exception handling to handle bad input.