Implemented vectorized implementation

Faster implementation!