Fixing a couple of bugs in the implementation