improved memory consumption and removed old code