Improved implementation.