debug and restructure