Rewrote from zero