code cleanup, moved comparison out of loop.