Rewrote everything and modularized it