refactor. rm a couple of bugs