Cleanup. Got rid of lots of warnings during compilation and some deprecated calls especially on MacOS X. Changed code tested on both Mac OS X and Linux.