Huge refactoring
Fixed formatting recursion bug