big refactor (sorry everyone)