Adding select algorithm and adding vars where necessary