Backup of @yjchen's ri_cal fork