Abstract logic from change_map function into new function.