replaced a couple of linear searches with binary searches and achieved a many (4-5) times speed up