refactored and rewrote a bunch