Fix several bugs from refactor