Refactored Code and better Comments