Fixing some bugs in the code.