major refactoring, additional speed functionality