minor fixes in code logic + junit tests