Done with refactor. Lots of bugs though