Algorithm working correctly.... just need to format output