fix #4 and some bugs