Bugfixes. Fixed various minor bugs