Minor refactoring and fix for warnings