Moved common code out into a gem