improve code, add default behaviour, and add flags: -p -e