Major code cleanup, opportunistic algorithm works