used velocity formula from stackoverflow