own function for writing varints