streamlined code and a little profiling