Some cleanup and performance improvments