Rename main func and move set -e to proper location