Fixing several issues in code