Adding debug info and a few optimizations

And lots of indentation tweaks.