Memory optimization (Credits to AOSPAL)