[BUGFIX beta] use Object.keys when possible

closes #4675 
I think there should be a test somehow, but I don't know how to test that