ported code to pdo's