Some duplicated code removed