major speed update and code cleanup