Fixed some typos, CS errors and refactoring repetitive code