Fixing miscellaneous bugs