Refactored, removed duplication