Improvements and bug fixes to MainActivity