fixed typos and refactored more