improved performance and corrected returned endmember results
organized code, removed unnecessary code, improved figure saving
minor corrections made