Fixed minor bugs affecting edge cases