Minor changes, some bugs fixed