code clean up and added more comments for ease of use and reading