Some refactoring. Added JMX capabilities