complete rewrite using module pattern