Refactor setState