Split the messy funtion into small ones.