Cleanup/refactor

Will probably do some more work; a few more improvements to be made here and there