Refactor. Move methods for working with registry and process \into lib