First bet working. TODO lots of cleanup and verification.