cleaned up gen. god damnit that was hard