refactor to better decouple state object from directives