fix bugs and delete testing code