Test and main edge cases fixed