modified for larger use case and edge case