Fixed bug when creating scalar expanded data. Fixed some comments and moved a variable into anonymous namespace