correction of code refactoring on detecting boxes funcions