seems to be working, merged handlePWG into the code (used existing functionality)