changed copyright. added contributors. rewrite logic and make up code style