Initial somewhat working implementation.