Better serializeId implementation that takes empty strings into consideration and fixed a logic error in isNaN(id) check