Massive refactor, supports 2.3+