Cleanup and speed improvement