First working version. Needs a lot of review.