remove repeated code