Improved and optimized hash implementation.