fixed bugs in code