replaced variable 'm' with 'i' where appropriate