Added code to detect front and back pages