Reworked generateNewId() to first consume new ids and later on recycle.