Refactored for readability
Better documentation