Refactor loading pins part of pinry.js to fix some bugs