Some fixes to DB session to prevent bound session errors and lock errors