Added a small debugging system as well as nice error reporting.
Fixed some minor misc issues.