modified to return a self reference
code clean up and added documentation