move common patterns out