Reorganize and bug fix