Major refactoring + PAM wip