Sanitize code (deprecated has_key) and PEP8 compliance