Refactored the entire source