added error checking, fixed href null value check