fixed bugs, and tested