Fixed error calculations
Fixed malloc bug