first part of sqlalchemy
more sql fixes
hopefully make threading die less often