First working version. No UI however.