Removed debugger
Added better logic for error handling. Fixed #2