Slightly improved code organization