added logging and better error handling