added support for master db, multiple bug fixes