re-structured the pinOk function and added comments