improved resize func