corrected typos, improved efficency