FIRST WORKING VERSION

Well, lots missing, lot of ugly code and rough edges, but it calculates