Changed function to calculate slope