first functional version

still has some work left to be done, but so far it does what's expected.