This is the first version that may do what it is supposed to. Starting to debug.