all key tests pass (only a few haven't been checked), but likely needs optimization