Added error handling & better logging