Refactoring

A bit of refactoring, encapsulation and food for thougts.