First working version. Needs polish.