Added more command line option checking and fixed PG connection code