Fixed an issue in the input function, refactored and tweaked IdentifyTriangle function.