refactoring some functions for issue #17
Add invert()