Added indices and refactored code

-added indices to foreign keys
-refactored code per review 9/10