Made vectorization more flexible and minor fixes.