Optimize expect.keys function