fixing bugs, almost done