small optimizations and polished test
fixed inverse edge funtion