Adds foreign key relationships to the database needed for faster
queries.
The problem reported in the last commit was indeed due to the
low number of returned records. Setting this number to 3 has removed the
problem.