added better try/catch and logging