Fixed the constructors and added listeners for background/foreground switches to stop rendering in the background