Fixed memory issues (WIP)