cleaning up the code and commenting