Refactoring capabilitymanager, adding tests