Working prototype. Now time to comment and clean.