Cherry picked 2 commits from the fork of koush