Added a little bit of validation and error handling