Fix some bugs, append utils for output from functions, some refactoring