cleaned up code for leg selection