Improvements to states.

Adding initial scalpmap support (not working yet).

Minor fixes / code style.