cleans up code and refactors; adds logic for speed points - both inperl and js