re-structure code