Alternate refactored implementation of #209

@YasuOza I felt that the code in the onload callback within fetchReplacement was getting messy, so I extracted the logic out into it's own method.  I figured it was easier to just make the changes myself rather than asking you to update your PR.  What do you think?