Add support for multiple selection and optimise code