adding if check before object.keys call