Clean up

Rewrote and organized some code