Code cleanup, added header comments