Refactored & commented a bit