fixing bugs, now it is working