Some code cleanup
Some refactoring
Merge branch 'master' into prototype