Commented working optimized version 1