Fixing Errors and cleaning up code.