Pre final version - commented, validated - still looking for bugs