speed improvements and cache optimization