Added index to Users, foreign keys, and did some other refactoring.