minor bug fixes and improvments

Same as #184 but without shared_ptr.