Full code review with some improvements.