Big refactor for python frontend layer