fixed bugs and tested working