Added some logic to handle an edge case presented by Marijn Mensinga