Fix 3 distinct bugs reported by Cristian Cadar.