Made a number of improvements in data.php including changes in error handling and how credentials are stored.