Huge cleanup, created a logging mechanism.