Refined code. Conformed scalastyle. fix interfaces. fix edge comparison.