cleaned up, added comments

No major functionality changes, cleaning of code, a few loose ends
fixed.