refactered varables generation; better error handling and tests for varables generation