Removed some bugs in the code.