Refactored the code and some extra things in the frontend