What about checking if $ak is object? Just in case $ak is not valid...