Fixed some bugs, split generator functions