Corrected survey function. Split all functions into separate files. Create main.r to call separate functions and init paramaters.