fixed name error and less code duplication