1) Updated version with the optimization