Refactored joinent logic and updated tests