Moved Logic out of MainActivity