Refactored class into smaller, more readable functions (incomplete)