eliminated all for loops when possible