Rename functions and split in smaller pieces for clarity