Add if-clause in get interval

Added a clause due to some issues with the swap function