Bug fixes after refactor