refactor code

add service layer