Initial code. Basic idea is in place.