added basic logging and error handling