Fix misc bugs