First very crude functioning version... various things
could go wrong including buffer overwriting right now.