Use constants instead of sizeof everywhere
Should be close to working
Oops. Was putting state into key map by accident