Use of smart pointer and some minor changes.