fixed a bug in generateNextId(context) method