Working Code, fixed b calculation