Remake structure, fix bugs