Adds pause on window losefocus event. Code cleanup to follow