Improve structure of python worker