Remove some duplicated logic