Refactored, commented, and facilitated 3rd-party use
Fix merge conflicts