Fixed a bug after refactoring