Add logging and fix bug in database naming