added copyright info, cleanup, refactoring, fixes