Major bugs fixed

Fix some major bugs, continue debug tomorrow...