final version with gems compat