Rewrote code with more idiomatic C++

e.g. inheritance