refactor and REST improvement