added some comments for clarity, considered done at this point