Refactor unique ID generator