It might be worth using keyword arguments and constants here, so that 0 and 2 aren't just magic numbers.