Refactor to simplify variable stashing.
Complete js unittests.