two optimizations can be made to reduce the time