slightly re-factored to use js module pattern