fix a lot of bugs but still there are some I think.