Added some error handling / validation