restructured code and added optimized selectors