functioning code, and cleaned up some