code optimization in several functions - Steve G