Cleaned up code. CSV will now correctly update the tables.