Added layer "states" dialog, fixes #27. Fixed several bugs.