added python functionality. Quiet a big refactor