replace call to mod with rem for better performance