Refactored, replace math.pow() with ** operator for better performance http://stackoverflow.com/questions/20969773/exponentials-in-python-x-y-vs-math-powx-y