Some refactoring, other misc things