try to avoid unnecessary malloc