Removed code duplication + verify that colnames function is available. Bug fix when evaluating length of var names.