COOPR-503: add junit tests and improve code