fixed #5 and fixed some bugs