refactored code for optimizing the frontend