optimize loops, algorithms, etc.

Also update coding style (it's my branch, now...)