Tidying and refactoring of the main activity