Added PageShown and PageHidden Lifecycle callbacks

I also refactored some code, added and refactored tests