Fixed check for valid ids