isolate the interesting part into lib/slave