Remove $wpdb declaration (no longer being used)
Clean up error handling code and add todos

Also it needed some adjusting for the post meta to get saved properly.