Fixed bugs in code