first "working" version.

much refactoring to do...