adding reactions requires less iteration w/ tests

Go through nested loops fewer times and get everything done on the first
iteration. Unit tests were also added to ensure proper behavior