added more mem efficent main