common functions files added
moved common functionality and error checking to common.c