cleaned up the code & added documentation