add null checks
add condition check for non-existing agent
Merge pull request #30 from anilsaldhana/master

see comments