Seems working now. Needs some overhaul of logging and the main file but other than that seems not half bad.