cleaned up and collapsed ps1 functions