first working version.
code must be cleaned up