minori fuckpaz

rewrite asmodean's code, fix some bug