added logging and try block