Refactor a bit and add additional check to class creation with array