Cleanup of value conversion code + better error message