Fix tests and improve performance by not using Sprintf