profiling and speed improvements