add proper error catch and logging