refactored to make duplicate code more obvious
created utility method to reduce code duplication