checkrails function destupified