a bit refactoring, added copyright