Move out duplicated code