some bugs fixed, work simplified