2314: refactor, arrange code