fix resize bug and leaks