tried to reduce complexity but it is not as nice as expected