Rewrote code and separated out concerns