Moved common code into a pcl library.

Use of generics throughout the library