fix bugs and improve junit tests