added optimized code