Fixing a few bugs in the initial implementation