adapted for browser; rewrote tests for jasmine