added -c switch and refactoring