Couldn't you move this out of the if statement, simplifying the code somewhat?