Refactored the before scene code