Fixed a couple of bugs, also introduced a new bug which we need to look at.