cleaned up end of atmos subroutine