shaped up code a bit