fixed some typos and refactored a little