Functionality Fix

Fully functional, and refactored in functions. Credit @asdfgh746 for
help debugging.