this function should be very easy to test, please add some tests for it.