wrote pi loop with convenience functions
Added in some comments