Bug fixes from refactor