App rewrite to avoid memory leak