Added prototypes for mac support.
Fixed seg.fault bug on mac. Refactored to remove duplicated code. Removed missing-return-statement warning.