Almost got it working. Just need to find why it breaks sometimes.