Bugfix to prevent cast error when closing resources and adjacent
function formatting update.