fixed bugs. still need to spend some time.