fixed logging and added basic error handling