refactor, return result to frontend