Use session factory in a better way