bugfix when allocating keys