fixed some bugs, implemented terminal functions and wrote more tests