fixed a few bugs in refactor