Change algorithm Enter and fix some bugs