(Almost done) pin refactoring