fixed #22, done part of #4, refactoring
merging