New function to avoid code repetition.