Lots of changes. Almost final version.