cleaned up restructure code