Minor Refactorings and fixes