Improve version handling code