Writing style adjusted to PEP. Few lines modified.