Refactoring & heavy optimization

For details check for "refactoring" branch, commits from 990645b to 416d7d5