Fix repeated code