HUGE refactoring in progress, trying to fix a bug now