added if condition for direction being NaN, and changed mult factor