Refactored triangle method