Added better error support
Merged in better error handling