optimized and extended version