Numerous refactoring bugfixes
WOOOOORDSSSS