reorganizing code a bit