fix different bugs, it works fine now