Removed some code duplication.