Modified to fix path issues as well as to support adjusting page number programmatically.