big rewrite for page handling, better, but still not happy with the structure