Refactored logging, added database switching.