Lots of changes. First working version.