fixing bugs from the refactor