take care of some edge cases, reduce complexity