refactor to use smarty and pdo a bit smarter