Use hasOwnProperty method.
Clean up some error cases.