Cleaned up a bit to work as an exercise for the PROJS group