Fixed flushChanges so that it also clears the changedEntities list.