Fixed some serious bugs