added indexes to foreign keys. fixed committing only once problem