First attempt at a smarter encoding.