Minor changes.
Added error handling function.