fix bugs and remove some never used code