move change directory into appropriate branch
Fix logic bug with insafemode check