more changes to fix some bugs found