Avoid string creation; eliminate some duplicated code