restructuring and a bit of shuffling. Output seems to be good for now