Cleaned up. Restructured code in modules.