first (maybe not so nice) attempt to re-partition the code