Removed unnecessary variable (halfRate). Tested code.