Implemented the original code from goolge.