These changes are same as the PR from #175  and fixes #170 

@drudge we can close #175