Rewrote with functions!