repolish code a bit