Added a console script and some bugfixes.