fix division by zero
fix segfault
remove legacy
fix