Giant dump of refactoring and stuff