fixed bugs and tested several functions