fixed logical and syntactical errors, math still is not right