The control flow of this function is structured terribly, but if you don't want to rewrite the whole function you should return -1 here.