Separate the logic out and be compatible with more ruby versions