A few performance improvements
Moved things around