issue #29

Issue #29 fix. This is olingern's solution (PR #34) using pure JS.