Refactoring following pruzand review.