Refactored how exceptions and errors are handled
Added global debug functions