fixing bug in demographic calculation script and adding common functionality folder