Fixing a few bugs in implementation.