Major refactoring, check diff.