First Refactor of ps1_function