added pagination for gallery and Douglas Peuker algorithm to simplify paths