Fixed some errors...

...added external functions