actually use the database class specified
fix infinite loop if session gets destroyed - kudos to @davidblondeau