Added -p option for page size and cleaned up scaling code