Minor refactoring, new bugs