added a range control, refactored JS