reorganizing code for a clearer separation