refactor main structure