added matthagy solution