Reorganize code (seg.cpp and seg.hpp)