Almost fixed, but some bug is in there