optimizing loops
removing incorrect optimization