refactoring
fixed critial depth bug