Initial attempt at cleanup (procedural style)