Code cleanup

See commit descriptions for the change log (I committed everything separately in small increments). This is mostly a cleanup commit, but includes removing old functions that are no longer used and replacing some pointers with boost shared_ptrs