faster implementation