Removed a lot of bugs in the code.