code refactoring - not sure if it's better