first commit, a bit late, mostly works, except for a few bugs here and there.