Add some guards and addressing code review feedback.