Some refactoring, still broken :).
Merge origin/master