Updated to be compatible with Python < 2.7