Implemented first version in JS.