Selection logic separated out, other minor changes