Refactoring variable declarations and scoping on public_spec