Implemented several bugfixes.