A bit hacky implementation of sprintf