Fixed a couple of bugs, so we need to write some tests - but this file is not supposed to be real code :-/