Fix bugs, reorganize