Adding db support and correcting some bug in variables