New version with several improvements.