add lock-state function + refactor + undeclared state error on functional impl