started conversion to PDO database usage, and misc code cleanup/structure