Restructured database tables and updated SQL to reflect changes