Fixed output and spelling erors and reorganized code