Move code which is only needed inside an if into it.