Improve gem install handling