fixed Jelly impl and refactored a few codes