Refactored to remove duplication and improved method and variable naming