edit and refactor MainActivity Code