Refactoring. Prepare for HTTP interface