tfixing subtle bugs