Bug fixes on errors caused by refactoring