Mem leak fixed; program runs in around 40 mins