Minor fixes to way SqlAlchemy is called so it works with large number of rows