Develop samples class

This is a huge pull request of the PSUL code. It has been validated for a long time an should not need further validation. The code is in need of a lot off cleaning and polishing. This will be done asap. However I suggest that you accept the pull request without digging into the code cleaning now since the new code contains bug fixes that need to be set int production asap.

Sorry for the huge request.