Fixed bug in formatResult function