Add some tests, fix some code

Really getting there too sloooowly...