Fixed a bug where running from another path and some refactoring

-Refactored error->err
-Fixed db filenames when not executing from root dir (as with init.d)