Some refactoring: encapsulation and more OO