Moved code to MainActivity