Refactor & add inline comments