#3 tested and fixed bugs