fix bugs, seems ok now