semi semi working
refactored for your reading pleasure
fucking minimax!!