Fix issue with target pool containing non-existent nodes.
Also some PEP8 and misc fixes