code moved over from rubabel