master, slave: make master and slave multithreaded

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>