Refactored code to blend with joya's api