fixed error bugs and tested