fix bugs, now it works