Split this into two separate functions.