updated protocol; some refactoring