Split this to its own function as well.