Added support for mean functions. Made extensive changes to how parameters are handled internally to support this and future expansion.