Added anti-hopper protection, and improve some code.