Fixed some issues in refactoring