Added indices to database and other optimisations