Adding proper error handling