Fixed more bugs in code