Tested and fixed output errors