@edchat pointed out that an indexOf test was incorrectly looking for 0 when something was not found, not -1. Rookie move. Fixed the issue and added a unit test to cover it.