Largely incomplete, but functional so far...