Fixed a few bugs; tested and works with -g & -e