Restructured the code and optimized some selectors