Refactoring to support reading PAM format
Support reading most PAM files
Cleanup to silence some compiler warnings