revised algorithms to deal with more complex flow cases; still need a good deal of trial and error