coded everything up until final sort and then array balancing. having compiled yet