Creating and assigning valid codes