Refactored parsePage method, breaking out a bunch of code into their own methods for clarity.