Fixed bug that occur after refactoring
Added debug code