Improved input->velocity code