Refactor and remove some code in mainActivity

-refactor the code
-remove unnecessary code