Refactor rejig function so it’s a bit clearer