move raw pointer to smart ptrs
minor refactoring of code layout