Massive restructure, added logging and improved output modules.