naive implementation of the edge cases
removed duplication