Improved debugging and catching exceptions and errors.
Also added few Exceptions.