Fixed errors not being caught
Improved error handling
Improved error handling