PENDING state, more tests, refactoring

/cc @ssalinas