added comments + refactored