Edit Swapped around the if statement and also moved the local remainder creation to after the if statement