added features to invert.cpp