A large number of fixed from CodeReview #306