Added a check to see if json_decode exists.
Changed keydir checks to include is_readable check.
Check added to key file that it is writable before attempt load
Added comments

Proposed changes:

1) Change the order of cache check (validate cache and present it first, rather than checking file exists + writable)
2) Update get_args to passed args instead?