Refactor Pages cache building

Theres still a lot of work, but it's allready a little bit cleaner