Moved some of the python logic to the Prolog logic - it is not working yet - the individual clauses are probably right, but getting them to work together is proving tricky - need a 'cut'?