fixed bugs, tested