Fix miscellaneous bugs