Tidy up of conversion logic, and handle in place for invalid input