Clean up and splitting up of functions due to crowding.