Some serious bugs fixed