Outsourced some duplicate code in Pre and Code