some bugs found and fixed