Improved manual implementation.