refactor to improve stability