Very rough functional version.