Code refractored. Added freeze checks.