generalized pattern loading code