Bugfixes and primitive plotting code