fixed error and tested thoroughly