That is not the code, that is a tiny snippet of what you have. Also doubtful, since you can't really be sure whether the inaccuracy is in software or hardware. You haven't performed any decisive tests to determine that yet.
Have you connected your setup to a calibrated pulse generator?