moving call to selection() outside of tight loop