Added saveHandler
Improved error handling