move scan state into scan code data structure
reorganize functions
simplify scan state transition function
use scan code state