major performance refactor