Fixed various minor bugs