fixed smalled errors and cleaned up code
 fixed small errors and cleaned up code