This seems to rely on the keys having already the add button index at the end already? Maybe it would be better for the caller to do this?