added Apply button and refactored