refactoring with asprintf