Small math change

Moved Distance to function.