added junit tests
bug fixes