Move scoped_session function out of __init__ and make it more generally useable.