fixed SGS_PATH ignoring bug, refactored and clarified errors