Enhanced the operation a bit and handled pipe from stdin properly