Fixed some bugs

but the code is not usable