Factor out key generating
Drop unused python code
Convert scripts to new code