Fix bugs from refactor