fixed bugs in code.