a lot of misc bug fixed and changes