Refactor, added error and CMS page support