Why am I refactoring this ghetto-ass code?