Optimize this code somewhat by taking advantage of the fact