Improved ID generation