refactor and simplify results javascript

Simplified + added tests