Random fixes
Minor refactoring