some cleanup before rewriting into C