Added MONITOR connection. Some refactoring.