optimise code and fix selectors