fix bugs, almost ok!