working code with multi-page setup