Fix bug, remove some unnecessary code