refactored js and kind of added search and post functionalities