Removed more calculations outside loop