Fixed activity lifecycle stuff - added comments and debug