Bug fixed, still heap memory exceeded