Bugfixes. Initial working version.