code clean up, fixed warnings, added some comments