Minor code refactoring, mostly cleanup. Added file headers.