WIP: Add indices and refactor code

-added indices to foreign keys