Vectorized the theta-calculations where possible