added a little logging and error handling