refactor ugly helper method