Fixed some subtle problems