Improved protocol and cleaned code a bit