Clean up and adapted version.