major code performance improvements