code clean up and fixes