Added autoPdf option and cleaned up code a little