link gem only when not already available, fix #2586, also small cleaning