Replaced intval() calls with a faster cast to int.