Fully rewrote the code with a clean architecture and comments