diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..40b878d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
\ No newline at end of file
diff --git a/.npmignore b/.npmignore
index cae62c7..1341949 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,4 +1,6 @@
 test/
-scripts/
+examples/
 *.json
 *.md
+appveyor.yml
+.travis.yml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..5358b12
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+language: node_js
+node_js:
+  - "node"
+  - "6"
+  - "4"
+  - "0.12"
+  - "0.10"
+
+# master + PRs
+branches:
+  only:
+    - master
diff --git a/LICENSE.md b/LICENSE.md
index 882ee66..c33860d 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2016 Nicholas McCready
+Copyright (c) 2016 Antti Pihlaja
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 7c8331a..4401a27 100644
--- a/README.md
+++ b/README.md
@@ -1,40 +1,79 @@
 # lazy-debug
 
-[![npm lazy-debug](https://nodei.co/npm/lazy-debug.png?compact=true)](https://www.npmjs.com/package/lazy-debug)
+[![Travis Build Status](https://travis-ci.org/apihlaja/lazy-debug.svg?branch=master)](https://travis-ci.org/apihlaja/lazy-debug) [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/yihkfbm7e89h1ngf/branch/master?svg=true)](https://ci.appveyor.com/project/apihlaja/lazy-debug/branch/master)
 
-Node.js module which generates app & module names for [visionmedia´s debug](https://github.com/visionmedia/debug) using `__filename` and package.json.
+**__UNMAINTAINED__**: this was developed for webpack v1, not tested since then (v4 is out now).
 
-Basic usage example:
+**lazy-debug** is a helper for [visionmedia´s debug](https://github.com/visionmedia/debug). It generates module identifiers based on `__filename`, so your debug identifiers reflect the file structure automatically.
+
+[![console log](https://raw.githubusercontent.com/apihlaja/lazy-debug/master/examples/express/output.png?raw=true)](https://github.com/apihlaja/lazy-debug/tree/master/examples/express)
+
+Supports
+
+  * Node.js v0.10 and later
+  * Windows and Linux
+  * Browserify
+  * Webpack
+
+## Install
+
+`npm install --save debug lazy-debug`
+
+The module works out of the box in Node.js and Browserify environments. 
+
+
+### Webpack
+
+Webpack needs [configuration](https://webpack.github.io/docs/configuration.html#node), include these in your `webpack.config.js`:
 
 ```javascript
-var debug = require('lazy-debug-legacy').get(__filename);
+config.node = {
+  __filename: true, // populates filenames relative to your app root
+  fs: "empty"       // include empty "mock" for fs module
+}
 ```
 
-Depending on `__filename`, debug name will be something like packageName:dir:file. File extension is removed and if file name is `index`, its removed too. For futher customization, to fit better for project structure, you can provide filter function:
+## Usage
+
+Just require it and provide filename:
 
 ```javascript
-var lazyDebug = require('lazy-debug-legacy');
-lazyDebug.configure({filter: function (pathArray) {
-  if ( pathArray[0] === 'src' ) {
-    pathArray.shift();
-  }
-  return pathArray;
-}});
-
-// now, when called in packageRoot/src/module1/index.js
-var debug = require('lazy-debug-legacy').get(__filename);
-// debug name will be projectName:module1
+var debug = require('lazy-debug')(__filename)
+debug('ready for logging..')
 ```
+Debugger identifier will be relative to module root, ie. something like `dir:file`. File extensions are omitted and file name is omitted if it´s `index`.
 
 
-## Install
+### Suffix
+
+Add suffix by providing `submoduleName`:
+
+```javascript
+var debug = require('lazy-debug')(__filename, {submoduleName: 'sub'})
+var debug = require('lazy-debug')(__filename, 'sub')
+```
+Debugger identifier will be `dir:file:sub`.
+
+
+### Prefix
+
+Add prefix by providing `packageName`:
+
+```javascript
+var debug = require('lazy-debug')(__filename, {packageName: 'my-lib'})
+var debug = require('lazy-debug')(__filename, {packageName: true})
+```
+
+Debugger identifier will be `my-lib:dir:file`. If package name is boolean `true`, name from `package.json` is used. That works only in Node.js environment.
 
-`npm install --save debug lazy-debug`
 
 ## Tests
 
 `npm test`
 
+Tests node.js compability by running vanilla [Mocha](https://mochajs.org/) at first, then Browserify and Webpack builds are tested in [PhantomJS](http://phantomjs.org/) using [Karma](http://karma-runner.github.io/).
+
+
 ## License
 
 [The MIT License](LICENSE.md)
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..fb82a62
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,30 @@
+version: "{build}"
+
+environment:
+  matrix:
+    - nodejs_version: "Stable" # latest
+    - nodejs_version: 6
+    - nodejs_version: 4
+    - nodejs_version: 0.12
+    - nodejs_version: 0.10
+
+platform:
+  - x64
+
+# master + PRs
+branches:
+  only:
+    - master
+
+install:
+  - ps: Install-Product node $env:nodejs_version
+  # tools versions
+  - node --version
+  - npm --version
+  # install modules
+  - npm install
+
+test_script:
+  - npm test
+
+build: off
\ No newline at end of file
diff --git a/debian/changelog b/debian/changelog
index 91535ef..3012e34 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+node-lazy-debug-legacy (0.3.0+git20180318.b22bc1a-1) UNRELEASED; urgency=medium
+
+  * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Thu, 28 Nov 2019 06:43:08 +0000
+
 node-lazy-debug-legacy (0.0.1-1) unstable; urgency=low
 
   * Initial release (Closes: #847155)
diff --git a/examples/express/README.md b/examples/express/README.md
new file mode 100644
index 0000000..6c52ce9
--- /dev/null
+++ b/examples/express/README.md
@@ -0,0 +1,5 @@
+# lazy-debug-example
+
+Slightly modified version of express-generator template to show off what this module does.
+
+![console log](https://raw.githubusercontent.com/apihlaja/lazy-debug/master/examples/express/output.png?raw=true)
diff --git a/examples/express/output.png b/examples/express/output.png
new file mode 100644
index 0000000..d9e4836
Binary files /dev/null and b/examples/express/output.png differ
diff --git a/examples/express/package.json b/examples/express/package.json
new file mode 100644
index 0000000..f558cbc
--- /dev/null
+++ b/examples/express/package.json
@@ -0,0 +1,17 @@
+{
+  "name": "lazy-debug-example",
+  "version": "0.0.0",
+  "private": true,
+  "scripts": {
+    "start": "node ./server/index.js"
+  },
+  "dependencies": {
+    "body-parser": "~1.15.2",
+    "cookie-parser": "~1.4.3",
+    "debug": "2.2.0",
+    "express": "~4.14.0",
+    "hbs": "~4.0.1",
+    "lazy-debug": "github:apihlaja/lazy-debug#dev",
+    "serve-favicon": "~2.3.0"
+  }
+}
diff --git a/examples/express/server/app.js b/examples/express/server/app.js
new file mode 100644
index 0000000..82b28f9
--- /dev/null
+++ b/examples/express/server/app.js
@@ -0,0 +1,52 @@
+var debug = require('lazy-debug')(__filename)
+
+debug('loading depedencies..')
+var express = require('express');
+var path = require('path');
+var favicon = require('serve-favicon');
+var cookieParser = require('cookie-parser');
+var bodyParser = require('body-parser');
+
+debug('loading routes..')
+var index = require('./routes/index');
+var users = require('./routes/users');
+
+debug('configuring express app..')
+var app = express();
+
+// view engine setup
+app.set('views', path.join(__dirname, 'views'));
+app.set('view engine', 'hbs');
+
+// uncomment after placing your favicon in /public
+//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({ extended: false }));
+app.use(cookieParser());
+app.use(express.static(path.join(__dirname, 'public')));
+
+app.use('/', index);
+app.use('/users', users);
+
+// catch 404 and forward to error handler
+app.use(function(req, res, next) {
+  debug('no match for ', req.url)
+  var err = new Error('Not Found');
+  err.status = 404;
+  next(err);
+});
+
+// error handler
+app.use(function(err, req, res, next) {
+  debug('error handler')
+
+  // set locals, only providing error in development
+  res.locals.message = err.message;
+  res.locals.error = req.app.get('env') === 'development' ? err : {};
+
+  // render the error page
+  res.status(err.status || 500);
+  res.render('error');
+});
+
+module.exports = app;
diff --git a/examples/express/server/index.js b/examples/express/server/index.js
new file mode 100644
index 0000000..12e2f25
--- /dev/null
+++ b/examples/express/server/index.js
@@ -0,0 +1,88 @@
+/**
+ * Module dependencies.
+ */
+
+var app = require('./app');
+var debug = require('lazy-debug')(__filename);
+var http = require('http');
+
+/**
+ * Get port from environment and store in Express.
+ */
+
+var port = normalizePort(process.env.PORT || '3000');
+app.set('port', port);
+
+/**
+ * Create HTTP server.
+ */
+
+var server = http.createServer(app);
+
+/**
+ * Listen on provided port, on all network interfaces.
+ */
+
+server.listen(port);
+server.on('error', onError);
+server.on('listening', onListening);
+
+/**
+ * Normalize a port into a number, string, or false.
+ */
+
+function normalizePort(val) {
+  var port = parseInt(val, 10);
+
+  if (isNaN(port)) {
+    // named pipe
+    return val;
+  }
+
+  if (port >= 0) {
+    // port number
+    return port;
+  }
+
+  return false;
+}
+
+/**
+ * Event listener for HTTP server "error" event.
+ */
+
+function onError(error) {
+  if (error.syscall !== 'listen') {
+    throw error;
+  }
+
+  var bind = typeof port === 'string'
+    ? 'Pipe ' + port
+    : 'Port ' + port;
+
+  // handle specific listen errors with friendly messages
+  switch (error.code) {
+    case 'EACCES':
+      console.error(bind + ' requires elevated privileges');
+      process.exit(1);
+      break;
+    case 'EADDRINUSE':
+      console.error(bind + ' is already in use');
+      process.exit(1);
+      break;
+    default:
+      throw error;
+  }
+}
+
+/**
+ * Event listener for HTTP server "listening" event.
+ */
+
+function onListening() {
+  var addr = server.address();
+  var bind = typeof addr === 'string'
+    ? 'pipe ' + addr
+    : 'port ' + addr.port;
+  debug('Listening on ' + bind);
+}
diff --git a/examples/express/server/public/stylesheets/style.css b/examples/express/server/public/stylesheets/style.css
new file mode 100644
index 0000000..9453385
--- /dev/null
+++ b/examples/express/server/public/stylesheets/style.css
@@ -0,0 +1,8 @@
+body {
+  padding: 50px;
+  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+  color: #00B7FF;
+}
diff --git a/examples/express/server/routes/index.js b/examples/express/server/routes/index.js
new file mode 100644
index 0000000..d7aa52d
--- /dev/null
+++ b/examples/express/server/routes/index.js
@@ -0,0 +1,11 @@
+var debug = require('lazy-debug')(__filename)
+var express = require('express');
+var router = express.Router();
+
+/* GET home page. */
+router.get('/', function(req, res, next) {
+  debug('rendering index')
+  res.render('index', { title: 'Express' });
+});
+
+module.exports = router;
diff --git a/examples/express/server/routes/users.js b/examples/express/server/routes/users.js
new file mode 100644
index 0000000..7722d07
--- /dev/null
+++ b/examples/express/server/routes/users.js
@@ -0,0 +1,11 @@
+var debug = require('lazy-debug')(__filename)
+var express = require('express');
+var router = express.Router();
+
+/* GET users listing. */
+router.get('/', function(req, res, next) {
+  debug('sending users')
+  res.send('respond with a resource');
+});
+
+module.exports = router;
diff --git a/examples/express/server/views/error.hbs b/examples/express/server/views/error.hbs
new file mode 100644
index 0000000..0659765
--- /dev/null
+++ b/examples/express/server/views/error.hbs
@@ -0,0 +1,3 @@
+<h1>{{message}}</h1>
+<h2>{{error.status}}</h2>
+<pre>{{error.stack}}</pre>
diff --git a/examples/express/server/views/index.hbs b/examples/express/server/views/index.hbs
new file mode 100644
index 0000000..1f308fd
--- /dev/null
+++ b/examples/express/server/views/index.hbs
@@ -0,0 +1,2 @@
+<h1>{{title}}</h1>
+<p>Welcome to {{title}}</p>
diff --git a/examples/express/server/views/layout.hbs b/examples/express/server/views/layout.hbs
new file mode 100644
index 0000000..068eb6b
--- /dev/null
+++ b/examples/express/server/views/layout.hbs
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>{{title}}</title>
+    <link rel='stylesheet' href='/stylesheets/style.css' />
+  </head>
+  <body>
+    {{{body}}}
+  </body>
+</html>
diff --git a/package.json b/package.json
index ce79068..0668257 100644
--- a/package.json
+++ b/package.json
@@ -1,74 +1,41 @@
 {
-  "name": "lazy-debug-legacy",
-  "version": "0.0.1",
-  "description": "Generates module names for vision media's debug",
+  "name": "lazy-debug",
+  "version": "0.3.0",
+  "description": "lazy-debug is a helper for visionmedia´s debug. It generates module identifiers based on filename, so your debug identifiers reflect the file structure automatically.",
   "main": "src/index.js",
   "scripts": {
-    "test": "mocha",
-    "print-test": "node scripts/print-test.js"
+    "test": "npm run test:nodejs && npm run test:browserify && npm run test:webpack",
+    "test:nodejs": "mocha",
+    "test:browserify": "karma start ./test/karma.browserify.js",
+    "test:webpack": "karma start ./test/karma.webpack.js"
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/apihlaja/lazy-debug.git"
+    "url": "https://github.com/apihlaja/lazy-debug.git"
   },
   "keywords": [
-    "debug"
+    "debug",
+    "webpack",
+    "browserify"
   ],
-  "author": {
-    "name": "Nicholas McCready"
-  },
-  "originalAuthor": {
-    "name": "Antti Pihlaja"
-  },
+  "author": "Antti Pihlaja",
   "license": "MIT",
   "peerDependencies": {
     "debug": "*"
   },
-  "dependencies": {},
+  "dependencies": {
+    "detect-node": "2.0.3"
+  },
   "devDependencies": {
+    "browserify": "^13.3.0",
     "chai": "^3.5.0",
-    "mocha": "^2.5.3"
-  },
-  "browserify": {
-    "transform": [
-      [
-        "babelify",
-        {
-          "presets": [
-            "es2015"
-          ]
-        }
-      ]
-    ]
-  },
-  "gitHead": "af1051caa0f3a201ec6cf28fe8919871233bd4b0",
-  "bugs": {
-    "url": "https://github.com/apihlaja/lazy-debug/issues"
-  },
-  "homepage": "https://github.com/apihlaja/lazy-debug#readme",
-  "_id": "lazy-debug@0.0.3",
-  "_shasum": "82cc2a6f4dcf36facf0c7a7946857bff62828ac7",
-  "_from": "lazy-debug@>=0.0.3 <0.0.4",
-  "_npmVersion": "2.14.2",
-  "_nodeVersion": "4.0.0",
-  "_npmUser": {
-    "name": "apihlaja",
-    "email": "antti.pihlaja@live.fi"
-  },
-  "dist": {
-    "shasum": "82cc2a6f4dcf36facf0c7a7946857bff62828ac7",
-    "tarball": "https://registry.npmjs.org/lazy-debug/-/lazy-debug-0.0.3.tgz"
-  },
-  "maintainers": [
-    {
-      "name": "apihlaja",
-      "email": "antti.pihlaja@live.fi"
-    }
-  ],
-  "_npmOperationalInternal": {
-    "host": "packages-16-east.internal.npmjs.com",
-    "tmp": "tmp/lazy-debug-0.0.3.tgz_1466088930341_0.7004884697962552"
-  },
-  "directories": {},
-  "_resolved": "https://registry.npmjs.org/lazy-debug/-/lazy-debug-0.0.3.tgz"
+    "karma": "^1.4.1",
+    "karma-browserify": "^5.1.0",
+    "karma-mocha": "^1.3.0",
+    "karma-phantomjs-launcher": "^1.0.2",
+    "karma-spec-reporter": "^0.0.30",
+    "karma-webpack": "^2.0.2",
+    "mocha": "^3.1.2",
+    "webpack": "^1.14.0"
+  }
 }
diff --git a/src/functions.js b/src/functions.js
deleted file mode 100644
index b980091..0000000
--- a/src/functions.js
+++ /dev/null
@@ -1,116 +0,0 @@
-var path = require('path');
-
-var functions = module.exports = {
-  parseFilePath: function (file, platform, filter) {
-    var delimiter = '/';
-    if (typeof platform == 'function') {
-      filter = platform;
-      platform = false;
-    }
-
-    if (!platform) platform = process.platform;
-    if (!platform) platform = 'browser';
-
-    if (platform === 'win32') {
-      delimiter = '\\';
-    }
-    if (platform === 'browser') {
-      if ( file.indexOf('\\') !== -1 ) {
-        delimiter = '\\';
-      }
-      if (file.indexOf('/') === 0) {
-        file = file.substr(1,file.length);
-      }
-    }
-    // should be posix..
-    var candidates = file.split(delimiter);
-    var modules = [];
-    for ( var i = 0; i < candidates.length; ++i ) {
-      if (candidates[i] && candidates[i].length ) {
-        modules.push(candidates[i]);
-      }
-    }
-    var last = modules.length - 1;
-    if ( last > 0 ) {
-      var fileName = removeFileExt(modules[last]);
-      if ( fileName === 'index' ) {
-        modules.pop();
-      } else {
-        modules[last] = fileName;
-      }
-    }
-    if ( modules.length > 0 ) {
-      if ( modules[0] === '..' ) {
-        modules.shift();
-      }
-    }
-    if ( filter && typeof filter === 'function' ) {
-      return filter(modules);
-    }
-    return modules;
-  },
-  locatePackageJson: function(filePath, platform) {
-    if (!platform) { platform = process.platform };
-    var pathParts = functions.parseFilePath(filePath, platform);
-    var filedir = path.dirname(filePath);
-    var testdir = filedir;
-    var counter = 1;
-    var result;
-    while (pathParts.length > counter ) {
-      try {
-        var testfile = path.join(testdir, 'package.json');
-        return require.resolve(testfile);
-      } catch( err ) {
-        // ignore
-      }
-      var testdir = path.resolve(testdir, '..');
-      counter++;
-    }
-    return false;
-  },
-  getModuleDebugId: function(filePath, options) {
-    options = options || {};
-
-    if (typeof options.platform == 'function') {
-      options.filter = platform;
-      options.platform = false;
-    }
-
-    if (!options.platform) { options.platform = process.platform };
-    var packagePath = functions.locatePackageJson(filePath, options.platform);
-    var relpath = (packagePath) ?
-      path.relative(packagePath, filePath) : functions.findModuleRoot(filePath);
-    var submodules = functions.parseFilePath(relpath, options.filter);
-
-    if (options.prependPackageName){
-      var packageName = (packagePath) ?
-        require(packagePath).name : functions.getPseudoName(filePath);
-      return packageName + ':' + submodules.join(':');
-    }
-    return submodules.join(':');
-  },
-  getPseudoName: function(filePath) {
-    var search = 'node_modules';
-    var idx = filePath.lastIndexOf(search);
-    if ( idx === -1 ) return 'app';
-    var moduleRoot = functions.findModuleRoot(filePath);
-    if ( filePath.lastIndexOf('node_modules/') !== -1 )
-      return moduleRoot.substr(0, moduleRoot.indexOf('/'));
-    else
-      return moduleRoot.substr(0, moduleRoot.indexOf('\\'));
-  },
-  findModuleRoot: function(filePath) {
-    var search = 'node_modules';
-    var idx = filePath.lastIndexOf(search);
-    if ( idx === -1 ) return filePath.substr(1);
-    return filePath.substr(idx+1+search.length);
-  }
-}
-
-function removeFileExt(fileName) {
-  var index = fileName.lastIndexOf('.');
-  if ( index !== -1 )
-    return fileName.substr(0, index);
-  else
-    return fileName;
-}
diff --git a/src/index.js b/src/index.js
index 9680edd..08c7e68 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,30 +1,188 @@
 var debug = require('debug');
-var getModuleDebugId = require('./functions').getModuleDebugId;
-var filter;
 
-var cache = {};
+var idCache = {};
+var pkgNameCache = {};
 
-var api = module.exports = {
-  configure: function(opts) {
-    if ( !opts ) opts = {};
-    if ( opts.filter && typeof opts.filter === 'function' ) {
-      filter = opts.filter;
-      cache = {};
+function get( filename, options ) {
+  return debug(getModuleDebugName(filename, options));
+}
+
+function getModuleDebugName( filename, options ) {
+  
+  var name = idCache[filename];
+  
+  options = options || {};
+  
+  if ( typeof options === 'string'  ) {
+    options = {submoduleName: options}
+  }
+
+  if ( !name ) {
+    name = getModuleDebugId(filename, {platform: process.platform});
+    idCache[filename] = name;
+  }
+  
+  if (options.submoduleName){
+    name += ':' + options.submoduleName;
+  }
+  
+  if (options.packageName) {
+    var pkgName;
+    
+    if (typeof options.packageName === 'string') {
+      pkgName = options.packageName;
     }
-  },
-  get: function( filename, submoduleName ) {
-    return debug(api.getModuleDebugName(filename, submoduleName));
-  },
-  getModuleDebugName: function ( filename, submoduleName ) {
-    var name = cache[filename];
-    if ( !name ) {
-      name = getModuleDebugId(filename, {platform: process.platform, filter:filter});
-      cache[filename] = name;
+    else {
+      pkgName = pkgNameCache[filename];
+      if (!pkgName) {
+        pkgName = getPackageName(filename);
+        pkgNameCache[filename] = pkgName;
+      }
     }
-    if ( submoduleName ) {
-      return name + ':' + submoduleName;
+    name = pkgName + ':' + name;
+  }
+  
+  return name;
+}
+
+// define public API
+
+get.get = get
+
+get.getModuleDebugName = getModuleDebugName
+
+module.exports = get
+
+// internals..
+
+var path = require('path');
+
+var fs;
+try {
+  fs = require('fs');
+} catch (e) {}
+ 
+
+var isNodeJs = require('detect-node');
+var isWin32 = isNodeJs && process.platform === 'win32'
+var isWebpack = !isNodeJs && (typeof process === 'undefined' || process.platform !== 'browser')
+
+function detectSeparator(file) {
+  if (isNodeJs) return path.sep;
+  
+  // try to guess in browser
+  if (file.indexOf('\\') !== -1) {
+    return '\\'
+  } else {
+    return '/'
+  }
+}
+
+function parseFilePath(file) {
+
+  var separator = detectSeparator(file)
+
+  if (separator === '\\' && file.indexOf('/') === 0) {
+    file = file.substr(1,file.length);
+  }
+  
+  var candidates = file.split(separator);
+  var modules = [];
+  for ( var i = 0; i < candidates.length; ++i ) {
+    if (candidates[i] && candidates[i].length ) {
+      modules.push(candidates[i]);
+    }
+  }
+  var last = modules.length - 1;
+  if ( last > 0 ) {
+    var fileName = removeFileExt(modules[last]);
+    if ( fileName === 'index' ) {
+      modules.pop();
     } else {
-      return name;
+      modules[last] = fileName;
+    }
+  }
+  if ( modules.length > 0 ) {
+    if ( modules[0] === '..' ) {
+      modules.shift();
+    }
+  }
+  return modules;
+}
+
+function locatePackageJson(filePath) {
+  var pathParts = parseFilePath(filePath);
+  var filedir = path.dirname(filePath);
+  var testdir = filedir;
+  var counter = 1;
+  var result;
+
+  // can't find in browserify/webpack build
+  if (!isNodeJs) return false;
+
+  while (pathParts.length > counter ) {
+    try {
+      var testfile = path.join(testdir, 'package.json');
+      if (fs.existsSync(testfile)) {
+        return testfile
+      }
+    } catch( err ) {
+      // ignore
     }
+    var testdir = path.resolve(testdir, '..');
+    counter++;
   }
-};
+  return false;
+}
+
+function getModuleDebugId(filePath, options) {
+  options = options || {};
+  
+  var packagePath = locatePackageJson(filePath);
+  var relpath = (packagePath) ?
+    path.relative(packagePath, filePath) : findModuleRoot(filePath);
+  var submodules = parseFilePath(relpath);
+
+  return submodules.join(':');
+}
+
+function getPackageName(filePath) {
+  var packagePath = locatePackageJson(filePath);
+
+  if (packagePath) {
+    return JSON.parse(fs.readFileSync(packagePath, {encoding: 'utf-8'})).name
+  } else {
+    return getPseudoName(filePath)
+  }
+}
+
+function getPseudoName(filePath) {
+  var search = 'node_modules';
+  var idx = filePath.lastIndexOf(search);
+  
+  if ( idx === -1 ) return 'app';
+  
+  var moduleRoot = findModuleRoot(filePath);
+  
+  if ( filePath.lastIndexOf('node_modules/') !== -1 )
+    return moduleRoot.substr(0, moduleRoot.indexOf('/'));
+  else
+    return moduleRoot.substr(0, moduleRoot.indexOf('\\'));
+}
+
+function findModuleRoot(filePath) {
+  var search = 'node_modules';
+  var idx = filePath.lastIndexOf(search);
+  if ( idx === -1 ) {
+    return (isWebpack) ? filePath : filePath.substr(1);
+  } 
+  return filePath.substr(idx+1+search.length);
+}
+
+function removeFileExt(fileName) {
+  var index = fileName.lastIndexOf('.');
+  if ( index !== -1 )
+    return fileName.substr(0, index);
+  else
+    return fileName;
+}
diff --git a/test/01-lazy-debug-test.js b/test/01-lazy-debug-test.js
new file mode 100644
index 0000000..c245044
--- /dev/null
+++ b/test/01-lazy-debug-test.js
@@ -0,0 +1,59 @@
+var expect = require('chai').expect;
+
+var isNodeJs = require('detect-node');
+
+describe('lazy-debug', function () {
+  var lazyDebug = require('../src');
+
+  it('is shortcut for #get', function () {
+    expect(lazyDebug).to.equal(lazyDebug.get);
+  });
+
+  describe('#get(filename, submoduleName|options)', function () {
+    it('returns named debug instance', function () {
+      lazyDebug.get(__filename)('this should be function');
+    });
+  });
+
+  describe('#getModuleDebugName(filename, submoduleName|options)', function () {
+    
+    it('gives debug name for file', function () {
+      var name = lazyDebug.getModuleDebugName(__filename);
+      expect(name).to.equal('test:01-lazy-debug-test');
+    });
+    
+    it('adds submodule name if given', function () {
+      
+      expect(
+        lazyDebug.getModuleDebugName(__filename, 'test2-1')
+      ).to.equal('test:01-lazy-debug-test:test2-1');
+      
+      expect(
+        lazyDebug.getModuleDebugName(__filename, {submoduleName: 'test2-2'}))
+      .to.equal('test:01-lazy-debug-test:test2-2');
+    });
+    
+    it('adds real package name in node.js', function () {
+      if (!isNodeJs) this.skip()
+      
+      expect(
+        lazyDebug.getModuleDebugName(__filename, {packageName: true})
+      ).to.equal('lazy-debug:test:01-lazy-debug-test');
+    });
+
+
+    it('uses "app" as package name in browser', function () {
+        if (isNodeJs) this.skip()
+
+        expect(
+          lazyDebug.getModuleDebugName(__filename, {packageName: true})
+        ).to.equal('app:test:01-lazy-debug-test');
+    })
+
+    it('sets package name if given', function () {
+      expect(
+        lazyDebug.getModuleDebugName(__filename, {packageName: 'fake'})
+      ).to.equal('fake:test:01-lazy-debug-test');
+    })
+  });
+});
diff --git a/test/dir1/index.js b/test/dir1/index.js
new file mode 100644
index 0000000..3e7d096
--- /dev/null
+++ b/test/dir1/index.js
@@ -0,0 +1,4 @@
+
+module.exports = function () {
+  return __filename;
+}
\ No newline at end of file
diff --git a/test/dir1/submodule1.js b/test/dir1/submodule1.js
new file mode 100644
index 0000000..3e7d096
--- /dev/null
+++ b/test/dir1/submodule1.js
@@ -0,0 +1,4 @@
+
+module.exports = function () {
+  return __filename;
+}
\ No newline at end of file
diff --git a/test/karma.browserify.js b/test/karma.browserify.js
new file mode 100644
index 0000000..4c5903c
--- /dev/null
+++ b/test/karma.browserify.js
@@ -0,0 +1,55 @@
+module.exports = function(config) {
+  config.set({
+    // base path that will be used to resolve all patterns (eg. files, exclude)
+    basePath: '../',
+
+    // frameworks to use
+    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
+    frameworks: ['browserify', 'mocha'],
+
+    // list of files / patterns to load in the browser
+    files: [
+      'test/**/*test.js'
+    ],
+
+    // list of files to exclude
+    exclude: [
+    ],
+
+    // preprocess matching files before serving them to the browser
+    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
+    preprocessors: {
+      'test/**/*.js': [ 'browserify' ]
+    },
+
+    // test results reporter to use
+    // possible values: 'dots', 'progress'
+    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+    reporters: ['spec'],
+
+    // web server port
+    port: 9876,
+
+    // enable / disable colors in the output (reporters and logs)
+    colors: true,
+
+    // level of logging
+    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+    logLevel: config.LOG_INFO,
+
+    // enable / disable watching file and executing tests whenever any file changes
+    autoWatch: false,
+
+    // start these browsers
+    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+    browsers: ['PhantomJS'],
+
+    // Continuous Integration mode
+    // if true, Karma captures browsers, runs the tests and exits
+    singleRun: true,
+
+    // Concurrency level
+    // how many browser should be started simultaneous
+    concurrency: Infinity
+  })
+}
diff --git a/test/karma.webpack.js b/test/karma.webpack.js
new file mode 100644
index 0000000..8ab9bc3
--- /dev/null
+++ b/test/karma.webpack.js
@@ -0,0 +1,63 @@
+module.exports = function(config) {
+  config.set({
+
+    // base path that will be used to resolve all patterns (eg. files, exclude)
+    basePath: '../',
+
+    // frameworks to use
+    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
+    frameworks: ['mocha'],
+
+    // list of files / patterns to load in the browser
+    files: [
+      'test/**/*test.js'
+    ],
+
+    // list of files to exclude
+    exclude: [
+    ],
+
+    // preprocess matching files before serving them to the browser
+    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
+    preprocessors: {
+      'test/**/*.js': [ 'webpack' ]
+    },
+
+    webpack: {
+      node: {
+        __filename: true,
+        "fs": "empty"
+      }
+    },
+
+    // test results reporter to use
+    // possible values: 'dots', 'progress'
+    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+    reporters: ['spec'],
+
+    // web server port
+    port: 9876,
+
+    // enable / disable colors in the output (reporters and logs)
+    colors: true,
+
+    // level of logging
+    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+    logLevel: config.LOG_INFO,
+
+    // enable / disable watching file and executing tests whenever any file changes
+    autoWatch: false,
+
+    // start these browsers
+    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+    browsers: ['PhantomJS'],
+
+    // Continuous Integration mode
+    // if true, Karma captures browsers, runs the tests and exits
+    singleRun: true,
+
+    // Concurrency level
+    // how many browser should be started simultaneous
+    concurrency: Infinity
+  })
+}
diff --git a/test/mocha.opts b/test/mocha.opts
new file mode 100644
index 0000000..5ada47b
--- /dev/null
+++ b/test/mocha.opts
@@ -0,0 +1 @@
+--reporter spec
diff --git a/test/print-script.js b/test/print-script.js
new file mode 100644
index 0000000..363496c
--- /dev/null
+++ b/test/print-script.js
@@ -0,0 +1,12 @@
+process.env.DEBUG = '*';
+var lazyDebug = require('../src');
+
+lazyDebug(__filename)('it works?');
+
+lazyDebug(__filename, 'sub')('debugger for submodule');
+
+lazyDebug(__filename, {packageName: true})('includes package name');
+
+lazyDebug
+  (__filename, {packageName: 'fake', submoduleName: 'sub2'})
+  ('fake package name + submodule');