Got the frontend mostly working - but may still re-write large portions if it is too hard to debug, since it is partly kludged.