Fixed various bugs relating to edge cases