refactored for triangle table