Refactored types, debug stuff and misc stuff into sepearte files