some bugs fixed after testing