Modified to support older version.
Refactored